package com.settlement.system.converter;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.settlement.system.common.enums.CostAllocationWeightEnum;
import org.apache.commons.lang3.StringUtils;

/**
 * 费用分配权数-权数类型
 * @author author
 */
public class WeightTypeConvert extends StringStringConverter {

    @Override
    public WriteCellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {

        if(!StringUtils.isEmpty(value)){
            return new WriteCellData(CostAllocationWeightEnum.WeightTypeEnum.getNameByNo(value));
        }
        return new WriteCellData();
    }

    @Override
    public String convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String value = super.convertToJavaData(cellData, contentProperty, globalConfiguration);
        if(!StringUtils.isEmpty(value)){
            return CostAllocationWeightEnum.WeightTypeEnum.getNoByName(value);
        }
        return null;
    }
}
